package com.ruoyi.web.controller.decision;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.decision.domain.Strategy;
import com.ruoyi.decision.service.IStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 优化策略Controller
 * 
 * @author zbw
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/decision/strategy")
public class StrategyController extends BaseController
{
    @Autowired
    private IStrategyService strategyService;

    /**
     * 查询优化策略列表
     */
    @PreAuthorize("@ss.hasPermi('decision:strategy:list')")
    @GetMapping("/list")
    public TableDataInfo list(Strategy strategy)
    {
        startPage();
        List<Strategy> list = strategyService.selectStrategyList(strategy);
        return getDataTable(list);
    }

    /**
     * 导出优化策略列表
     */
    @PreAuthorize("@ss.hasPermi('decision:strategy:export')")
    @Log(title = "优化策略", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Strategy strategy)
    {
        List<Strategy> list = strategyService.selectStrategyList(strategy);
        ExcelUtil<Strategy> util = new ExcelUtil<Strategy>(Strategy.class);
        util.exportExcel(response, list, "优化策略数据");
    }

    /**
     * 获取优化策略详细信息
     */
    @PreAuthorize("@ss.hasPermi('decision:strategy:query')")
    @GetMapping(value = "/{strategyId}")
    public AjaxResult getInfo(@PathVariable("strategyId") String strategyId)
    {
        return AjaxResult.success(strategyService.selectStrategyByStrategyId(strategyId));
    }

    /**
     * 新增优化策略
     */
    @PreAuthorize("@ss.hasPermi('decision:strategy:add')")
    @Log(title = "优化策略", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Strategy strategy)
    {
        return toAjax(strategyService.insertStrategy(strategy));
    }

    /**
     * 修改优化策略
     */
    @PreAuthorize("@ss.hasPermi('decision:strategy:edit')")
    @Log(title = "优化策略", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Strategy strategy)
    {
        return toAjax(strategyService.updateStrategy(strategy));
    }

    /**
     * 删除优化策略
     */
    @PreAuthorize("@ss.hasPermi('decision:strategy:remove')")
    @Log(title = "优化策略", businessType = BusinessType.DELETE)
	@DeleteMapping("/{strategyIds}")
    public AjaxResult remove(@PathVariable String[] strategyIds)
    {
        return toAjax(strategyService.deleteStrategyByStrategyIds(strategyIds));
    }
}
